package com.jiaxianm.secure.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class R<T> {
    private Integer code; // 状态码
    private String msg; // 消息
    private T data; // 数据

    // 成功响应
    public static <T> R<T> ok(T data) {
        return R.<T>builder()
                .code(200)
                .msg("成功")
                .data(data)
                .build();
    }

    public static R ok() {
        return R.builder()
                .code(200)
                .msg("成功")
                .build();
    }

    // 错误响应
    public static <T> R<T> error(Integer code, String msg) {
        return R.<T>builder()
                .code(code)
                .msg(msg)
                .build();
    }
}